package handler

import (
	"encoding/json"
	"gomonitor-server/src/db"
	"gomonitor-server/src/http/util"
	"io"
	"net/http"
)

type HostDeleteReq struct {
	IPList []string `json:"ip_list"`
}

func HostDeleteHandler(w http.ResponseWriter, r *http.Request) {
	var hostDeleteReq HostDeleteReq
	body, _ := io.ReadAll(r.Body)
	err := json.Unmarshal(body, &hostDeleteReq)
	if err != nil {
		util.ProcessResult("参数错误", err, w)
		return
	}
	err = db.HostDelete(hostDeleteReq.IPList)
	if err != nil {
		util.ProcessResult("", err, w)
	} else {
		util.ProcessResult("ok", nil, w)
	}

}
